<?php

session_start();

include_once "src/controller/blmanagement/ReportManagement.php";
include_once "src/controller/blmanagement/ResourceManagement.php";
include_once "src/model/User.php";
include_once "src/misc/ClientReponseGenerator.php";

try {

    $reportResult = ReportManagement::RptResourcesforPeriod("2005-01-01", "2020-01-01");

    $values = "";
    $titles = "";
    $reportResultCount = count($reportResult);
    for ($i = 0; $i < $reportResultCount; $i++) {
        $tempReportItem = $reportResult[$i];

        $values .= $tempReportItem[1];
        $titles .= $tempReportItem[0];

        if (($reportResultCount > 1) && (($i + 1) < $reportResultCount)) {
            $values .= ",";
            $titles .= "|";
        }
    }
    
    if ($reportResultCount == 0) {
        throw new Exception();
    } else {
        echo "{\"success\":\"1\", \"report\":\"<img alt='Yellow pie chart' src='http://chart.apis.google.com/chart?cht=p&chs=600x400&chd=t:$values&chdl=$titles&chtt=Resource+Used+Frequency+Report'>\", \"message\":\"".""."\"}";
    }

} catch (Exception $e) {
    echo ClientReponseGenerator::simpleJsonResponse(0, "GetAllResourcesException", "");
}

?>
